from pms.common.views import PostFormula
from user.models import User


class API(PostFormula):

    require_permissions = [6]

    def handle(self, req):
        uid = req['id']
        password = req['password']
        user = User.objects.get(id=uid)
        if user == self.user:
            self.assert_one_of_permissions([5, 6])
        else:
            self.assert_permissions([6])
        user.__dict__.update(password=password)
        user.save()
        return self.success_respond({
            'id': user.id
        })
